﻿using System;
using System.Configuration;

namespace SBACN.WebSite.Common
{
	public class HostSetting
	{
		/// <summary>
		/// 网站相对根路径
		/// </summary>
		public static string RootPath
		{
			get
			{
				if(!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["RootPath"]))
				{
					string rootPath = ConfigurationManager.AppSettings["RootPath"].Trim();
					return rootPath.EndsWith("/") ? rootPath : rootPath + "/";
				}
				throw new Exception("Web.config文件缺少配置信息，或配置信息不正确：AppSettings/RootPath");
			}
		}

		/// <summary>
		/// 管理系统相对路径
		/// </summary>
		public static string AdminPath
		{
			get
			{
				if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["RootPath"]))
				{
					string adminPath = ConfigurationManager.AppSettings["AdminPath"].Trim();
					return RootPath + (adminPath.EndsWith("/") ? adminPath : adminPath + "/");
				}
				throw new Exception("Web.config文件缺少配置信息，或配置信息不正确：AppSettings/AdminPath");
			}
		}

		/// <summary>
		/// 文件上传的根路径
		/// </summary>
		public static string UploadRootPath
		{
			get
			{
				if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["UploadRootPath"]))
				{
					string uploadRootPath = ConfigurationManager.AppSettings["UploadRootPath"].Trim();
					return RootPath + (uploadRootPath.EndsWith("/") ? uploadRootPath : uploadRootPath + "/");
				}
				throw new Exception("Web.config文件缺少配置信息，或配置信息不正确：AppSettings/UploadRootPath");
			}
		}

		/// <summary>
		/// 文件上传大小，单位M
		/// </summary>
		public static int MaxUploadSize
		{
			get
			{
				int maxSize = 0;
				if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["MaxUploadSize"]) && int.TryParse(ConfigurationManager.AppSettings["MaxUploadSize"], out maxSize))
				{
					return maxSize;
				}
				throw new Exception("Web.config文件缺少配置信息，或配置信息不正确：AppSettings/MaxUploadSize");
			}
		}

		/// <summary>
		/// 允许上传的文件类型
		/// </summary>
		public static string UploadFileTypes
		{
			get
			{
				if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["UploadFileTypes"]))
				{
					return ConfigurationManager.AppSettings["UploadFileTypes"].Trim().ToLower();
				}
				throw new Exception("Web.config文件缺少配置信息，或配置信息不正确：AppSettings/UploadFileTypes");
			}
		}

		/// <summary>
		/// 管理系统的默认页
		/// </summary>
		public static string AdminDefaultPage
		{
			get
			{
				if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["AdminDefaultPage"]))
				{
					return AdminPath + ConfigurationManager.AppSettings["AdminDefaultPage"].Trim();
				}
				throw new Exception("Web.config文件缺少配置信息，或配置信息不正确：AppSettings/AdminDefaultPage");
			}
		}

		/// <summary>
		/// 管理系统的登录页URL
		/// </summary>
		public static string AdminLoginPage
		{
			get
			{
				if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["AdminLoginPage"]))
				{
					return AdminPath + ConfigurationManager.AppSettings["AdminLoginPage"].Trim();
				}
				throw new Exception("Web.config文件缺少配置信息，或配置信息不正确：AppSettings/AdminLoginPage");
			}
		}

		/// <summary>
		/// 网站默认页
		/// </summary>
		public static string MemberDefaultPage
		{
			get
			{
				if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["MemberDefaultPage"]))
				{
					return RootPath + ConfigurationManager.AppSettings["MemberDefaultPage"].Trim();
				}
				throw new Exception("Web.config文件缺少配置信息，或配置信息不正确：AppSettings/MemberDefaultPage");
			}
		}

		/// <summary>
		/// 网站登录页URL
		/// </summary>
		public static string MemberLoginPage
		{
			get
			{
				if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["MemberLoginPage"]))
				{
					return RootPath + ConfigurationManager.AppSettings["MemberLoginPage"].Trim();
				}
				throw new Exception("Web.config文件缺少配置信息，或配置信息不正确：AppSettings/MemberLoginPage");
			}
		}
	}
}